#include <iostream>

class Code {
public:
  void forget(int code) {
    if (code == 0xFACE) {
      throw std::runtime_error("Invalid code");
    }
    printf("Forgot code: 0x%X\n", code);
  }
};

void useTryCatch() {
  Code code;
  try {
    code.forget(0x1234);
    code.forget(0xFACE);
    code.forget(0xC0DE);
  } catch (const std::runtime_error &e) {
    printf("Caught exception: %s\n", e.what());
  }
}

int main(int argc, char *argv[]) {
  std::cout << "==== ch04 p03 ====" << std::endl;
  printf("---- useTryCatch() ----\n");
  useTryCatch();
  return 0;
}
